package com.article.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BaseAction extends ActionSupport implements ServletResponseAware {
	private HttpServletResponse response;
	private static final Logger logger = Logger.getLogger(BaseAction.class);

	/**
	 * 将json数据输出到客户端
	 * 
	 * @param json
	 */
	public void outJson(String json) {
		PrintWriter out = null;
		try {
			response.setContentType("text/html;charset=utf-8");
			out = response.getWriter();
			out.print(json);
			out.flush();
			out.close();
		} catch (IOException ex) {
			logger.error("向客户端输出信息失败！原因：" + ex.getMessage());
		} finally {
			out.close();
		}
	}

	public void setServletResponse(HttpServletResponse arg0) {
		response = arg0;
	}

}
